3 // Copyright (C) 2005 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file erase_fn_imps.hpp
42 * Contains an implementation class for ov_tree_.
46 inline typename PB_ASSOC_CLASS_C_DEC::size_type
47 PB_ASSOC_CLASS_C_DEC::
48 erase(const_key_reference r_key)
50 iterator it = find(r_key);
62 PB_ASSOC_CLASS_C_DEC::
65 PB_ASSOC_DBG_ONLY(assert_valid();)
69 PB_ASSOC_DBG_ONLY(assert_valid();)
75 cond_dtor cd(m_a_values, m_end_it, m_size);
78 PB_ASSOC_DBG_ONLY(my_map_debug_base::clear();)
84 m_end_it = m_a_values;
86 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
88 PB_ASSOC_DBG_ONLY(assert_valid();)
93 inline typename PB_ASSOC_CLASS_C_DEC::size_type
94 PB_ASSOC_CLASS_C_DEC::
97 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
99 #ifdef PB_ASSOC_BASIC_REGRESSION
100 throw_prob_adjustor adjust(m_size);
101 #endif // #ifdef PB_ASSOC_BASIC_REGRESSION
103 size_type new_size = 0;
105 size_type num_val_ersd = 0;
107 iterator source_it = m_a_values;
109 for (source_it = begin(); source_it != m_end_it; ++source_it)
111 if (pred(*source_it))
121 return (num_val_ersd);
124 pointer a_new_values = s_alloc.allocate(new_size);
126 iterator target_it = a_new_values;
128 cond_dtor cd(a_new_values, target_it, new_size);
130 PB_ASSOC_DBG_ONLY(my_map_debug_base::clear());
132 for (source_it = begin(); source_it != m_end_it; ++source_it)
134 if (!pred(*source_it))
136 new (const_cast<void* >(
137 static_cast<const void* >(target_it)))
138 value_type(*source_it);
140 PB_ASSOC_DBG_ONLY(my_map_debug_base::insert_new(
141 PB_ASSOC_V2F(*source_it)));
150 cond_dtor cd1(m_a_values, m_end_it, m_size);
153 m_a_values = a_new_values;
157 m_end_it = target_it;
159 PB_ASSOC_DBG_ONLY(assert_valid();)
161 return (num_val_ersd);
167 PB_ASSOC_CLASS_C_DEC::
170 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)
176 PB_ASSOC_CLASS_C_DEC::check_key_exists(PB_ASSOC_V2F(*it));)
178 #ifdef PB_ASSOC_BASIC_REGRESSION
179 throw_prob_adjustor adjust(m_size);
180 #endif // #ifdef PB_ASSOC_BASIC_REGRESSION
182 PB_ASSOC_DBG_ASSERT(m_size > 0);
184 pointer a_values = s_alloc.allocate(m_size - 1);
186 iterator source_it = begin();
187 iterator source_end_it = end();
188 iterator target_it = a_values;
189 iterator ret_it = end();
191 cond_dtor cd(a_values, target_it, m_size - 1);
193 PB_ASSOC_DBG_ONLY(size_type cnt = 0;)
195 while (source_it != source_end_it)
199 PB_ASSOC_DBG_ONLY(++cnt;)
200 PB_ASSOC_DBG_ASSERT(cnt != m_size);
202 new (const_cast<void* >(
203 static_cast<const void* >(target_it)))
204 value_type(*source_it);
217 PB_ASSOC_CLASS_C_DEC::erase_existing(PB_ASSOC_V2F(*it));)
219 cond_dtor cd1(m_a_values, m_end_it, m_size);
222 m_a_values = a_values;
226 m_end_it = m_a_values + m_size;
228 update(node_begin(), (Node_Updator* )this);
230 PB_ASSOC_DBG_ONLY(PB_ASSOC_CLASS_C_DEC::assert_valid();)